package com.neusoft.bizcore.activiti.fixture;

import java.util.List;

import org.activiti.editor.language.json.converter.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.activiti.constants.BizcoreActivitiConstants;
import com.neusoft.bizcore.activiti.model.ActSerialNumber;
import com.neusoft.bizcore.activiti.repository.ActSerialNumberRepository;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@Order(value = 10)
public class ActFixture implements CommandLineRunner {

    @Autowired
    private ActSerialNumberRepository serialNumberRepository;

    @Override
    public void run(final String... args) throws Exception {
        ActFixture.log.info("初始化工作流开始");

        final List<ActSerialNumber> list = this.serialNumberRepository.findAll();
        if (CollectionUtils.isEmpty(list)) {
            final ActSerialNumber model = new ActSerialNumber();
            model.setConfigTemplet("GD${DATE}0000000");
            model.setIsAutoIncrement("0");
            model.setMaxSerial("0");
            model.setModuleCode(BizcoreActivitiConstants.WORK_ORDER_MODEL_CODE_KEY);
            model.setPreMaxNum("100");
            model.setModuleName("工单号");
            this.serialNumberRepository.save(model);
        }

        ActFixture.log.info("初始化工作流结束");
    }

}
